﻿namespace EFS.RC.CC.Deployment.Tables.Tools
{
	public static class Supervisors
	{
		/// GetByOfficeEndPointID
		public static EFS.RC.CC.Deployment.Entities.Operators.Supervisor[] GetByOfficeEndPointID(System.Int32 officeEndPointID)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteTableReaderQuery<EFS.RC.CC.Deployment.Entities.Operators.Supervisor>(
					"[dbo].[Supervisors_GetByOfficeEndPointID]",
					new EFS.DB.Parameters.Array("office_endpoint_id", officeEndPointID),
					EFS.RC.CC.Deployment.Tables.DataRow.Operators.Supervisor.Load);
			}
		}

		/// GetByID
		public static EFS.RC.CC.Deployment.Entities.Operators.Supervisor GetByID(System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// get data
				return connection.DoExecuteRowReaderQuery<EFS.RC.CC.Deployment.Entities.Operators.Supervisor>(
					"[dbo].[Supervisors_GetByID]",
					new EFS.DB.Parameters.Array("id", id),
					EFS.RC.CC.Deployment.Tables.DataRow.Operators.Supervisor.Load);
			}
		}

		/// Create
		public static System.Int32? Create(
			System.Int32 officeEndPointID,
			System.Guid domainOid,
			System.String domainLogonName)
		{
			// make params
			EFS.DB.Parameters.Array parametersArray = new EFS.DB.Parameters.Array(
				new System.String[] { "office_endpoint_id", "domain_oid", "domain_logon_name", "id" },
				new System.Object[] { officeEndPointID, domainOid, domainLogonName, default(System.Int32)},
				new System.Boolean[] { false, false, false, true });
			
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				// ok
				connection.DoExecuteNonQuery("[dbo].[Supervisors_Create]", parametersArray);
			}

			// get id value
			return parametersArray.GetOutPrameterValue<System.Int32?>("id"); 
		}

		/// Update
		public static void Update(
			System.Int32 id,
			System.String domainLogonName)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				connection.DoExecuteNonQuery(
					"[dbo].[Supervisors_Update]",
					new EFS.DB.Parameters.Array(
						new System.String[] { "id", "domain_logon_name" },
						new System.Object[] { id, domainLogonName }));
			}
		}

		/// Delete
		public static void Delete(
			System.Int32 id,
			EFS.DB.Connection connection)
		{
			// check
			EFS.Common.Verify.Reference(connection, "connection");

			// delete
			connection.DoExecuteNonQuery("[dbo].[Supervisors_Delete]", new EFS.DB.Parameters.Array("id", id));
		}

		//Delete without transaction
		public static void Delete(
			System.Int32 id)
		{
			// handle connection
			using (EFS.DB.Connection connection = EFS.RC.CC.Deployment.Connection.New1)
			{
				Delete(id, connection);
			}
		}
	}
}